package edu.whut.service.impl;

import edu.whut.dao.ReciteDao;
import edu.whut.entity.Recite;
import edu.whut.service.ReciteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReciteServiceImpl implements ReciteService {

    @Resource
    ReciteDao reciteDao;

    @Override
    public List<Recite> getRecitedPoem(Long userId) {
        Map<String,Object> map=new HashMap<>();
        map.put("isRecite",1);
        map.put("userId",userId);
        List<Recite> recites = reciteDao.selectByMap(map);
        return recites;
    }

    @Override
    public List<Recite> getUnRecitedPoem(Long userId) {
        Map<String,Object> map=new HashMap<>();
        map.put("isRecite",0);
        map.put("userId",userId);
        List<Recite> recites = reciteDao.selectByMap(map);
        return recites;
    }

    @Override
    public Boolean isRecite(Long userId, Long poemId) {
        Map<String,Object> map=new HashMap<>();
        map.put("userId",userId);
        map.put("poemId",poemId);
        List<Recite> recites = reciteDao.selectByMap(map);
        return recites!=null;
    }

    @Override
    public Boolean addRecite(Recite recite) {

        return reciteDao.insert(recite)>0;
    }

    @Override
    public Boolean deleteRecite(Long userId, Long poemId) {
        Map<String,Object> map=new HashMap<>();
        map.put("userId",userId);
        map.put("poemId",poemId);
        return  reciteDao.deleteByMap(map)>0;
    }

    @Override
    public Boolean updateRecite(Recite recite) {
        return reciteDao.updateById(recite)>0;
    }
}
